package com.blx.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.blx.entity.User;
import com.blx.model.response.LoginResponse;
import com.blx.service.QUserService;

public class CheckLoginController extends BaseController{

	@Autowired
	private QUserService quserService;
	private static final Logger logger = LoggerFactory.getLogger(CheckLoginController.class);
	/**
	 * 
	 * @Description: TODO ajax请求 判定用户是否登陆
	 */
	@ResponseBody
	@RequestMapping("checkLogion")
	public LoginResponse checkLogin(HttpServletRequest request,HttpServletResponse response) {
		LoginResponse loginResponse = new LoginResponse();
		try {
			HttpSession session = request.getSession(true);
			User user = (User) session.getAttribute("SESSION_USER");
			if(user == null){
				loginResponse.setStatus(0);
				loginResponse.setResponseCode(200);
				return loginResponse;
			}else{
				loginResponse.setStatus(1);
				loginResponse.setResponseCode(200);
				return loginResponse;
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("",e);
			loginResponse.setResponseCode(500);
			return loginResponse;
		}
	}
}
